import time
from selenium.webdriver.support.wait import WebDriverWait

from base.get_logger import GetLogger

logger = GetLogger().get_logger()

class Base:

    def __init__(self,driver):
        logger.info("初始化driver{}".format(driver))
        self.driver = driver

    def base_find_element(self,loc,timeout=30,poll_frequerncy=0.5):
        logger.info("正在查找元素{}".format(loc))
        return WebDriverWait(self.driver,
                             timeout=timeout,
                             poll_frequency=poll_frequerncy).until(lambda x:x.find_element(*loc))

    def base_click(self,loc):
        logger.info("正在点击元素{}".format(loc))
        self.base_find_element(loc).click()

    # def base_input(self,loc,value):
    #     logger.info("正在给元素{}输入：{}".format(loc,value))
    #     el = self.base_find_element(loc)
    #     logger.info("正在给{}元素清空".format(loc))
    #     el.clear()
    #     logger.info("正在给元素{}输入：{}".format(loc,value))
    #     el.send_keys(value)

    def base_get_result(self,loc):
        logger.info("正在获取元素{}的属性".format(loc))
        return self.base_find_element(loc).get_attribute("value")

    def base_get_screensot(self,case):
        logger.info("正在截图")
        # self.driver.get_screenshot_as_file("../image/{}.jpg".format(time.strftime("%Y_%m_%d_%H_%M_%S")))
        self.driver.get_screenshot_as_file("../image/{}.jpg".format(case))
